<!DOCTYPE html>
<html class="loginHtml">
<head>
    <meta HTTP-EQUIV="pragma" CONTENT="no-cache">
    <meta HTTP-EQUIV="Cache-Control" CONTENT="no-store, must-revalidate">
    <meta HTTP-EQUIV="expires" CONTENT="0">
	<meta charset="utf-8">
	<title>Metacompta</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=devicfavicon.icoe-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
<!--	<link rel="icon" href="/favicon.ico">-->
	<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
	<link rel="stylesheet" href="/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="/css/public.css" media="all" />
    <script type="text/javascript" src="/layui/layui.js"></script>
    <script type="text/javascript" src="/js/lib/md5.js"></script>
	<style type="text/css">
		::placeholder { /* Firefox, Chrome, Opera */
			color: red;
			font-size: 16px;
		}

		:-ms-input-placeholder { /* Internet Explorer 10-11 */
			color: red;
			font-size: 16px;
		}

		::-ms-input-placeholder { /* Microsoft Edge */
			color: red;
			font-size: 16px;
		}
	</style>
</head>
<body class="loginBody">
	<form class="layui-form" onkeydown="if(event.keyCode==13) return false;">
		<div class="login_face"><img src="/images/face2.jpg" class="userAvatar"></div>
		<div class="layui-form-item input-item">
			<label for="jobNumber">员工工号</label>
			<input type="text" placeholder="请输入员工工号" autocomplete="off" id="jobNumber" class="layui-input" lay-verify="required">
		</div>
		<div class="layui-form-item input-item">
			<label for="password">密码</label>
			<input type="password" placeholder="请输入密码" autocomplete="off" id="password" class="layui-input" lay-verify="required">
		</div>
		<div class="layui-form-item">
			<button class="layui-btn layui-block" lay-filter="login" lay-submit>登录</button>
		</div>
	</form>
</body>
<script type="text/javascript">
    layui.use(['form','layer','jquery'],function(){
        var form = layui.form,
                layer = parent.layer === undefined ? layui.layer : top.layer
        $ = layui.jquery;

		//获取登录的用户信息
		function getUserInfo( callback){
			$.ajaxSettings.async = false;
			$.get("/adminUser/getUserInfo",function( res){
				if( res.code == 200){
					callback( res.data);
				}else if( res.code == 304){
					top.layer.confirm( "用户尚未登录，点击跳转到登录页面", function(){
						window.location.href = "/pages/login.html";
					});
				}else{
					top.layer.alert( res.msg);
				}
			});
		}
        //登录按钮
        form.on("submit(login)",function(data){
        	var btn = $(this)
            $(btn).text("登录中...").attr("disabled","disabled").addClass("layui-disabled");
            $.post("/adminUser/login",{
                "jobNumber" : $("#jobNumber").val(),
                "password" : hex_md5( $("#password").val())
            },function( res){
				$(btn).text("登录").removeAttr("disabled").removeClass( "layui-disabled");
                if( res.code == 200){
					var userInfo= {};
					getUserInfo( function( data){
						userInfo = data;
					});

					//将用户信息缓存起来
					window.sessionStorage.setItem( "userInfo", JSON.stringify( userInfo));
                    top.layer.msg( res.msg);
                    window.location.href = "/pages/index.html";
                }else if( res.code == 203){//用户未审核
					top.layer.msg( res.msg);
				}else{
                    top.layer.msg( res.msg);
                }
            });
        });

        //表单输入效果
        $(".loginBody .input-item").click(function(e){
            e.stopPropagation();
            $(this).addClass("layui-input-focus").find(".layui-input").focus();
        });
        $(".loginBody .layui-form-item .layui-input").focus(function(){
            $(this).parent().addClass("layui-input-focus");
        });
        $(".loginBody .layui-form-item .layui-input").blur(function(){
            $(this).parent().removeClass("layui-input-focus");
            if($(this).val() != ''){
                $(this).parent().addClass("layui-input-active");
            }else{
                $(this).parent().removeClass("layui-input-active");
            }
        });
        $("#goRegistBtn").click(function () {
			window.location.href = "/pages/register.html";
		});
    });
</script>
</html>
